package com.hao_family.atcrowdfunding.controller.permission;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hao_family.atcrowdfunding.beans.TAdmin;
import com.hao_family.atcrowdfunding.constant.AppConstant;
import com.hao_family.atcrowdfunding.service.AdminService;

@Controller
public class PermissionController {
	/**
	 * 负责页面跳转
	 */
	@Autowired
	AdminService adminService;
	
	/**
	 * 1.接受admin页面请求
	 * pn-->第几页
	 * ps-->每页数目
	 * condition-->查询条件
	 */
	
	@GetMapping("/admin/index.html")
	public String goToMainPage(Model model,
			@RequestParam(value="condition",defaultValue="")String condition,
			@RequestParam(value="pn",defaultValue="1")Integer pn,
			@RequestParam(value="ps",defaultValue=AppConstant.DEFAULT_PAGE_SIZE)Integer ps,
			HttpSession session
			) {
		session.setAttribute(AppConstant.QUERY_CONDITION_KEY, condition);
		session.setAttribute("pn", pn);
		PageHelper.startPage(pn, ps);
		List<TAdmin> list = adminService.getAdminList(condition);
		PageInfo<TAdmin> pageInfo = new PageInfo<TAdmin>(list,AppConstant.DEFAULT_PAGEFOOT_SIZE);
		model.addAttribute(AppConstant.PAGEINFO_ADMINLIST, pageInfo);
		return "permission/admin";
	}
	
	/**
	 * 2.接受role页面请求
	 */
	@GetMapping("/role/index.html")
	public String goToRolePage() {
		return "permission/role";
	}
	
	/**
	 * 3.接受permission页面请求
	 */
	@GetMapping("/permission/index.html")
	public String goToPermissionPage() {
		return "permission/permission";
	}
	
	/**
	 * 4.接受menu页面请求
	 */
	@GetMapping("/menu/index.html")
	public String goToMenuPage() {
		return "permission/menu";
	}
	
	
}
